package com.qianfeng.openapi.web.master.mapper;

import com.qianfeng.openapi.web.master.pojo.Menu;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface MenuMapper {
    int deleteByPrimaryKey(Integer id);

    int insert(Menu record);

    int insertSelective(Menu record);

    Menu selectByPrimaryKey(Integer id);

    int updateByPrimaryKeySelective(Menu record);

    int updateByPrimaryKey(Menu record);

    // 查询左侧导航菜单信息
    @Select("select\n" +
            "\t*\n" +
            "from\n" +
            "\tmenu m inner join role_menu rm on m.id = rm.MENU_ID\n" +
            "\tinner join user_role ur on rm.ROLE_ID = ur.ROLE_ID\n" +
            "where\n" +
            "\tm.TYPE between 0 and 1\n" +
            "\tand ur.USER_ID = #{userId}")
    List<Menu> findLeftSideNavMenu(@Param("userId") Integer userId);

    // 查询全部
    @Select("select * from menu order by SORT,TYPE")
    List<Menu> findAll();

    // 查询数据总条数
    @Select("select count(0) from menu")
    Long findCount();

    // 根据用户id查询菜单信息
    List<Menu> findByUserId(Integer userId);


    @Select("select * from menu where type between 0 and 1")
    List<Menu> findAllByTypeZeroToOne();
}